<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form autocomplete="off">
    姓名：<input type="text" id="username">
    <span id="uSpan"></span>
    <br>
    密码：<input type="password" id="password">
    <br>
    <input type="submit" value="注册">
</form>
</body>
<script src="js/jquery-3.3.1.min.js"></script>
<script>
    //ajax中get方法
   /* $.get(
        "userServlet",
        "id="+1,
        function (data) {
            alert(data)
        },
        "text"
    );*/
    //ajax中post方法
    //失去焦点触发事件
    $("#username").blur(function () {
        $.post(
            "userServlet",
            "username=" + $("#username").val(),
            function (data) {
                alert(data)
            },
            "text"
        );
    });
</script>
</html>